const Home = () => import("@/pages/Home");
const Search = () => import("@/pages/Search");
const Login = () => import("@/pages/Login");
const Register = () => import("@/pages/Register");
const Detail = () => import("@/pages/Detail");
const NotFound = () => import("@/pages/404");
const ShopCart = () => import("@/pages/ShopCart");
const AddCartSuccess = () => import("@/pages/AddCartSuccess");
const Trade = () => import("@/pages/Trade");
const Pay = () => import("@/pages/Pay");
const PaySuccess = () => import("@/pages/PaySuccess");
const Center = () => import("@/pages/Center");
const MyOrder = () => import("@/pages/Center/components/MyOrder");
const TeamOrder = () => import("@/pages/Center/components/TeamOrder");

export default [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: Home,
    name: "Home",
  },
  {
    path: "/search/:keyword?",
    component: Search,
    name: "Search",
  },
  {
    path: "/login",
    component: Login,
    name: "Login",
    meta: {
      isFooterHidden: true,
    },
  },
  {
    path: "/register",
    component: Register,
    name: "Register",
    meta: {
      isFooterHidden: true,
    },
  },
  {
    path: "/detail/:skuId",
    component: Detail,
    name: "Detail",
    meta: {
      isFooterHidden: true,
    },
  },
  {
    path: "/addcartsuccess",
    component: AddCartSuccess,
    name: "AddCartSuccess",
    beforeEnter: (to, from, next) => {
      if (from.name === "Detail") {
        next();
      } else {
        next("/home");
      }
    },
  },
  {
    path: "/shopcart",
    component: ShopCart,
    name: "ShopCart",
    meta: {
      isFooterHidden: true,
    },
  },
  {
    path: "/trade",
    component: Trade,
    name: "Trade",
    beforeEnter: (to, from, next) => {
      if (from.name === "ShopCart") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/pay/:orderId",
    component: Pay,
    name: "Pay",
    meta: {
      isFooterHidden: true,
      isAuth: true,
    },
    beforeEnter: (to, from, next) => {
      if (from.name === "Trade") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/paysuccess",
    component: PaySuccess,
    name: "PaySuccess",
    meta: {
      isFooterHidden: true,
      isAuth: true,
    },
    beforeEnter: (to, from, next) => {
      if (from.name === "Pay") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/center",
    component: Center,
    name: "Center",
    meta: {
      isFooterHidden: true,
      isAuth: true,
    },
    redirect: "/center/myOrder",
    children: [
      {
        path: "myOrder",
        name: "MyOrder",
        component: MyOrder,
        meta: {
          isAuth: true,
        },
      },
      {
        path: "teamOrder",
        name: "TeamOrder",
        component: TeamOrder,
        meta: {
          isAuth: true,
        },
      },
    ],
  },
  {
    path: "*",
    component: NotFound,
    name: "NotFound",
  },
];
